from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
#显示等待：判断每个要操作的元素是否出现，出现则做操作，不出现则抛出异常。
from selenium.webdriver.support.wait import WebDriverWait
#导入预期判定条件
from selenium.webdriver.support import  expected_conditions
driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
driver.maximize_window()
#1.判断一个元素是否完成加载,expected_conditions.presence_of_element_located((By.ID,"account"))
#传入浏览器对象driver,设置元素等待时间
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"account")))
driver.find_element(By.ID,"account").send_keys("123456")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.NAME,"password")))
driver.find_element(By.NAME,"password").send_keys("123456")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID,"submit")))
driver.find_element(By.ID,"submit").click()
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'/html/body/div[1]/div[1]/div/ul[1]/li[8]/button')))
driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div/ul[1]/li[8]/button').click()
# 查看元素是否可用并切入框架
WebDriverWait(driver,10).until(expected_conditions.frame_to_be_available_and_switch_to_it("iframe-superadmin"))
#判断元素中的value属性是某个值
# expected_conditions.text_to_be_present_in_element_value()
# 判断元素中的attribute属性名是某个值
# expected_conditions.text_to_be_present_in_element_attribute()
# 判断超链接中是否包含预期文本
# expected_conditions.text_to_be_present_in_element()
# 判断是否出现弹出框
# expected_conditions.alert_is_present()
# 弹出框：元素无法定位的
# 1.切入到弹出框,并存入变量alert: alert=driver.switch_to.alert()
# 2.获取到弹出框文本信息      alert.text
# 3.点击确认按钮  alert.accept()
# 4.点击取消按钮  alert.dismiss()
# 5.输入给弹出框的文本框 alert.send_keys()
# driver.switch_to.frame("iframe-superadmin")
WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH,'/html/body/div[2]/div/div/div[1]/div/a/h3')))
driver.find_element(By.XPATH,'/html/body/div[2]/div/div/div[1]/div/a/h3').click()
driver.quit()